<?php

class authenticationActions extends sfActions {

    public function executeIndex(sfWebRequest $request){
        
    }

    public function executeLogin(sfWebRequest $request){
        if(!$this->getUser()->isAuthenticated()){
            $user = $request->getParameter('user');
            $password = $request->getParameter('password');

            $configuration = ConfigurationPeer::doSelectOne(new Criteria());

            if($user == $configuration->getAdminUser() && md5($password) == $configuration->getAdminPassword()){
                $this->getUser()->setAuthenticated(true);
            }else{
                $this->getUser()->setFlash('message','Los datos ingresados son incorrectos. Inténtelo nuevamente');
            }
        }
        $this->redirect('@homepage');
    }

    public function executeLogout(sfWebRequest $request){
        $this->getUser()->setAuthenticated(false);
        $this->getUser()->getAttributeHolder()->clear();
        $this->redirect('@homepage');
    }

}